import { createRouter, createWebHashHistory } from 'vue-router';

const routes = [
    // {
    //     name: 'notFound',
    //     path: '/:path(.*)+',
    //     redirect: {
    //         name: 'login',
    //     },
    // },
    {
        name: 'login',
        path: '/login',
        component: () => import('./views/Login.vue'),
        meta: {
            title: '登录'
        }
    },
    {
        path: '/store',
        name: 'store',
        meta: {
            title: '门店配置'
        },
        component: () => import('./views/Store.vue')
    },
    {
        path: '/banner',
        name: 'banner',
        meta: {
            title: '首页轮播图'
        },
        component: () => import('./views/Banner.vue')
    },
    {
        path: '/works-type',
        name: 'works-type',
        meta: {
            title: '地点管理'
        },
        component: () => import('./views/WorksType.vue')
    },
    {
        path: '/work-type',
        name: 'work-type',
        meta: {
            title: '分类管理'
        },
        component: () => import('./views/WorkType.vue')
    },
    {
        path: '/works',
        name: 'works',
        meta: {
            title: '作品配置'
        },
        component: () => import('./views/Works.vue')
    },
    {
        path: '/work',
        name: 'work',
        meta: {
            title: '作品配置'
        },
        component: () => import('./views/Work.vue')
    },
    {
        path: '/user',
        name: 'user',
        meta: {
            title: '用户配置'
        },
        component: () => import('./views/User.vue')
    },
    {
        path: '/server',
        name: 'server',
        meta: {
            title: '服务配置'
        },
        component: () => import('./views/Server.vue')
    },
    {
        path: '/server2',
        name: 'server2',
        meta: {
            title: '服务配置（新）'
        },
        component: () => import('./views/Server2.vue')
    },
    {
        path: '/server-category',
        name: 'server-category',
        meta: {
            title: '服务分类'
        },
        component: () => import('./views/ServerCategory.vue')
    },
    {
        path: '/quotation',
        name: 'quotation',
        meta: {
            title: '报价管理'
        },
        component: () => import('./views/Quotation.vue')
    },
    {
        path: '/quotation-category',
        name: 'quotation-category',
        meta: {
            title: '服务分类'
        },
        component: () => import('./views/QuotationCategory.vue')
    },
];

const router = createRouter({
    routes,
    history: createWebHashHistory(),
});

router.beforeEach((to, from, next) => {
    const title = to.meta && to.meta.title;
    if (title) {
        document.title = `华德培后台管理-${title}`;
    }
    next();
});

export { router };
